﻿@using OASystem.Model;
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="~/css/tail.css" rel="stylesheet" type="text/css" />
    <link href="~/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body style="border-radius: 8px" onload="change()">
    <!--<div class="title"><h2>通知详情</h2></div>-->
    <div id="form_demo">
        <div class="top">
            <div>
                <div class="top_out">
                    <table class="table">
                        <tbody>
                            <tr>
                                <td style="border-top: none">职位名称：<i class="i_start"></i></td>
                                <td colspan="6" style="text-align: left;border-top: none"><input type="text" id="PosName" name="name" minlength="2" required></td>
                            </tr>
                            <tr>
                                <td>上级职位ID：</td>
                                <td style="text-align: left">
                                    <input class="long_text" type="text" id="ParentId" />

                            </tr>
                            <tr>
                                <td>所属部门：</td>
                                <td style="text-align: left">
                                    <select id="DepartId">
                                        @if (ViewBag.List != null)
                                        {
                                            foreach (Departinfo item in ViewBag.List)
                                            {
                                                <option value="@item.DepartId">@item.DepartName</option>
                                            }
                                        }

                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td style="line-height: 240px">描述：</td>
                                <td colspan="8" style="text-align: left"><input id="Describe" style="width: 100%;height: 240px" /></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="bot_btn">
                <input class="btn" id="addbtn" type="button" value="保存" />
                <button class="btn btn1">返回</button>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="~/js/jquery.js"></script>
<script type="text/javascript" src="~/js/demo/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="~/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="~/js/jquery.ztree.exedit-3.5.js"></script>
<script src="~/js/layer.js"></script>
<script>
    var sendID, sendName, zTree, nodes
    $(function () {
        /*  Tree()*/
    })
    //DOM树初始化setting设置
    var setting = {
        check: {
            enable: true
        },
        data: {
            key: { name: "MODULENAME" },
            simpleData: {
                enable: true,
                idKey: "MODULEID",
                pIdKey: "pIdKey",
                rootPId: null
            }
        },
        callback: {
            onCheck: onCheck
        }
    };

    /*  //加载DOM树数据方法
      function Tree() {
          $.ajax({
              type: "POST",
              url: '../RoleManage/GetFunctionModuleList',
              dataType: "~/json",
              success: function (result) {
                  if (result) {
                      var nodes = result.data;
                      var item = { "MODULENAME": "权限目录", "pIdKey": "-1" };
                      nodes.push(item);
                      $.fn.zTree.init($("#treeDemo"), setting, nodes);
                      zTree = $.fn.zTree.getZTreeObj("treeDemo");
                      zTree.expandAll(true);
                  }
              }
          });
      }*/
    function onCheck(e, treeId, treeNode) {
        nodes = zTree.getCheckedNodes()
    };
    function RoleSave() {
        var RoleName = $("#RoleName").val();
        var RoleMS = $("#RoleMS").val();
        var v = "";
        for (var i = 1; i < nodes.length; i++) {
            if (i == nodes.length - 1) {
                v += nodes[i].MODULEID;
            } else {
                v += nodes[i].MODULEID + ",";
            }
        }
        $.ajax({
            type: "POST",
            url: '../RoleManage/AddPermission',
            dataType: "~/json",
            data: { ID: "-1", NAME: RoleName, VALUE: v, DESCRIBE: RoleMS },
            success: function (result) {
                if (result) {
                    alert("保存成功")
                    parent.getRoleTableData();
                    checkCancel();
                }
            }
        });
    }
    function checkCancel() {
        zTree.checkAllNodes(false);
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }



    /*角色管理添加方法*/
    $(function () {
        $("#addbtn").click(function () {
            var data = {};
            data.PosName = $("#PosName").val();
            data.Describe = $("#Describe").val();
            data.ParentId = $("#ParentId").val();
            data.DepartId = $("#DepartId").val();
            var name = data.PosName;
            $.ajax({
                type: "post",
                url: "/Role_Tail/QueryRole?name=" + name,
                success: function (result) {
                    if (result.success) {
                        layer.msg('职位名称重复!', { icon: 6, time: 1000 });
                    } else {
                        $.ajax({
                            type: "post",
                            url: "/Role_Tail/AddRole",
                            data: data,
                            success: function (operate) {
                                if (operate.Success) {
                                    layer.msg('添加成功!', { icon: 6, time: 1000 });
                                    window.location.href = "/Home/Role";
                                } else {
                                    layer.msg('发现错误!', { icon: 6, time: 1000 });
                                }
                            }
                        })
                    }
                }
            })

        })
    })
</script>
</html>
